<template>
	<view class="content">
		<u-navbar back-text="" title="">
			<view style="width: 100%;display: flex;justify-content: center;font-weight: bold;font-size: 34rpx;">
				发布朋友圈
			</view>
			<view slot="right">
				<view style="margin-right: 30rpx;">
					<view @click="fabucon" v-if="title"
						style="width: 100rpx;height: 50rpx;background: #1893ff;color: white;display: flex;align-items: center;justify-content: center;border-radius: 8rpx;">
						发布
					</view>
					<view v-else
						style="width: 100rpx;height: 50rpx;background: #8acdff;color: white;display: flex;align-items: center;justify-content: center;border-radius: 8rpx;">
						发布
					</view>
				</view>
			</view>
		</u-navbar>

		<view style="width: 100%;padding: 35rpx;">
			<u-input v-model="title" type="textarea" placeholder="发布内容..."></u-input>
		</view>

		<view style="width: 100%;padding: 35rpx;display: flex;align-items: center;flex-wrap: wrap;">
			<view v-for="(item,k) in images" style="width: 210rpx;height: 210rpx;margin-right: 10rpx;">
				<image :src="$store.state.common.systemInfo.fileurl + item" style="width: 210rpx;height: 210rpx;"
					mode=""></image>
				<image @click.stop="remove(item)" src="/static/images/ddel.png"
					style="width: 40rpx;height: 40rpx;position: relative;bottom: 210rpx;left: 170rpx;" mode=""></image>
			</view>

			<view v-if="images.length < 9" @click="uploadimage"
				style="width: 210rpx;height: 210rpx;display: flex;align-items: center;justify-content: center;background: #e3e3e3;">
				<u-icon name="plus" size="70"></u-icon>
			</view>
		</view>

		<view style="width: 100%;padding: 35rpx;display: flex;align-items: center;justify-content: space-between;">
			<u-cell-group>
				<u-cell-item icon="integral-fill" title="设置权限" @click="show = true" :value="type"></u-cell-item>
			</u-cell-group>
			<u-action-sheet @click="selecttype" :list="listhd" v-model="show"></u-action-sheet>
		</view>
	</view>


</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		pub
	} from '../../common/event';
	import utils from '../../utils';
import moment from 'moment/moment';
	export default {
		data() {
			return {
				show: false,
				type: '公开',
				title: '',
				listhd: [{
					text: "公开"
				},{
					text: "好友"
				}, {
					text: "私有"
				}],
				images: []
			}
		},
		components: {

		},
		computed: {
			...mapState({

			})
		},
		onLoad() {
			this.getdata()
		},
		methods: {
			getdata: function() {},
			fabucon: async function() {
				const user = uni.getStorageSync("user")
				const data = {
					name:user.name,
					uid:user.id,
					title:this.title,
					type:this.type,
					images:JSON.stringify(this.images),
					time:moment().valueOf()
				}
				const ret = await this.$u.post(`friend/friend/addpyqinfo`,data)
				uni.showToast({
					title:"发布成功"
				})
				uni.switchTab({
					url:"/pages/news/index"
				})
			},
			uploadimage: async function(e) {
				const _this = this
				uni.chooseImage({
					count: 9,
					async success(res) {
						uni.showLoading({
							title:"上传中.."
						})
						console.log(res)
						for(let o of res.tempFilePaths){
							const ret = await utils.uploadImage(o)
							console.log(ret)
							if (ret && ret.success && ret.data) {
								_this.images.push(ret.data.pathname)
							}
						}
						uni.hideLoading()
					}
				})
			},
			remove: function(item) {
				this.images = this.images.filter(e => e != item)
			},
			selecttype: async function(e) {
				console.log(e)
				this.type = this.listhd[e].text
			},
		}
	}
</script>


<style scoped>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 100%;
		height: 100vh;
		overflow-y: auto;
		padding-bottom: 120rpx;
		background: white;
	}
</style>